package com.xcity.game.task.detector;

import com.xcity.db.entity.Player;
import com.xcity.game.task.Task;
import com.xcity.game.task.TaskDetector;
import com.xcity.game.task.TaskDetectorLabel;

/**
 * <pre>
 * 获得道具
 * 2n个参数:
 * 1.道具1id
 * 2.道具1数量
 * …
 * 2n-1.道具nid
 * 2n.道具n数量
 * </pre>
 * @author yang.li
 *
 */
@TaskDetectorLabel(TaskDetector.GET_ITEM)
public class GetItemTaskDetector implements TaskDetector {

	@Override
	public boolean isFinish(Task task) {
		int[] conds = task.getTemplate().getConditions();
		Player player = task.getVm().getOwner(); // TODO 玩家下线时有可能导致这里获取的player为Actor
		for (int i = 0; i < conds.length; i += 2) {
			int id = conds[i];
			int count = conds[i + 1];
			if (player.getBag().countOf(id) < count) {
				return false;
			}
		}
		return true;
	}

	@Override
	public void onArchive(Task task, Object... vals) {

	}

}
